package com.sx.zongzhi.adapter;


import android.content.Context;
import android.widget.TextView;

import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.OrganizingBean;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

/**
 * Created by XZY on 2017/11/23.
 * 选择当前位置的adapter
 */
public class LocalDataAdapter extends CommonAdapter<OrganizingBean> {

    private int selectItem;
    private Context context;
    private boolean setSelector=false;

    public LocalDataAdapter(Context context, int layoutId, List<OrganizingBean> datas) {
        super(context, layoutId, datas);
        this.context=context;
    }

    public void setItemBackground(int position){
        setSelector=true;
        selectItem=position;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(ViewHolder viewHolder, OrganizingBean item, int position) {
        TextView textView=viewHolder.getView(R.id.tv_Content);
        textView.setText(item.getName());
        if (setSelector) {
            if (selectItem == position) {
                textView.setBackgroundColor(context.getResources().getColor(R.color.white));
            } else {
                textView.setBackgroundColor(context.getResources().getColor(R.color.background));
            }
        }
    }
}
